package com.luckku.boot.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luckku.boot.common.api.ApiResult;
import com.luckku.boot.model.dto.RepairReqDTO;
import com.luckku.boot.model.entity.RepairRequest;
import com.luckku.boot.model.vo.RepairReqVO;
import com.luckku.boot.service.IRepairReqService;
import com.luckku.boot.utils.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author luckku
 * @date 2021/11/23
 */

@Controller
@RequestMapping("/repair")
public class RepairReqController {


    @Autowired
    SnowFlakeUtil snowFlakeUtil;

    @Autowired
    IRepairReqService repairReqService;
    /**
     * /repair/addReqByDTO
     * 根据信息添加物资
     */
    @ResponseBody
    @PostMapping("/addReqByDTO")
    public ApiResult<RepairRequest> addReqByDTO(@RequestBody RepairReqDTO dto) {

        RepairRequest request = RepairRequest.builder()
                .repairId(String.valueOf(snowFlakeUtil.snowflakeId()))
                .applicantName(dto.getApplicantName())
                .itemName(dto.getItemName())
                .damagedLevel(dto.getDamagedLevel())
                .details(dto.getDetails())
                .location(dto.getLocation())
                .tel(dto.getTel())
                .build();
        repairReqService.save(request);
        return ApiResult.success(request);
    }

    /**
     * /wrhsGoods/getOutWrhsList
     * 获取出库历史信息（用于出库历史展示页）
     *
     * @return ApiResult<List < OutWarehouseDetailVO>>
     */
    @ResponseBody
    @GetMapping("/getReqList")
    public ApiResult<IPage<RepairReqVO>> getOutWrhsList(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                        @RequestParam(value = "size", defaultValue = "10") Integer pageSize) {
        IPage<RepairReqVO> repairReqList = repairReqService.getReqList(new Page<>(pageNo, pageSize));
        return ApiResult.success(repairReqList);
    }

}
